package top.roadvast.springboot.base64_test.utils;

import org.apache.commons.codec.binary.Base64;

import java.nio.charset.StandardCharsets;

/**
 * 使用Codec实现base64算法
 */
public class CodecBase64Util {

    public static String encode(String str) {
        byte[] result = Base64
                .encodeBase64(str.getBytes(StandardCharsets.UTF_8));
        return new String(result, StandardCharsets.UTF_8);
    }

    public static String decode(String encodeStr) {
        byte[] decode = Base64.decodeBase64(encodeStr);
        return new String(decode, StandardCharsets.UTF_8);
    }
}